package org.xbug.search.woody.core.model;

import java.util.Map;

import org.xbug.search.woody.core.util.FastJsonExt;

import com.alibaba.fastjson.JSONObject;

/**
 * 动态页面模板（提供模板到数据源得映射）
 * @author xuzhengtao
 *
 */
public abstract class DynamicModel extends Model{
	
	public DynamicModel() {
		
	}

	public DynamicModel(JSONObject dataSource) {
		this.dataSource = dataSource;
		initSourceKeyMap();
	}
	
	protected JSONObject dataSource;
	
	protected Map<String,String> sourceKeyMap;

	/**
	 * 转换成真实数据
	 */
	protected abstract void tranferData();
	
	/**
	 * 根据伪数据获取真实数据
	 * @param fake
	 * @return
	 */
	protected String getRealValue(String fake) {
		return FastJsonExt.getChildString(sourceKeyMap.get(fake), dataSource);
	}
	
	/**
	 * 初始化数据源映射关系键值对
	 */
	protected abstract void initSourceKeyMap();
	
	protected void initSourceKeyMap(JSONObject dataSource) {
		this.dataSource = dataSource;
		initSourceKeyMap();
	}
}
